﻿<UserControl x:Class="Passwords.Views.LoginView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:models="clr-namespace:Passwords.Models"
             xmlns:controls="clr-namespace:Passwords.Controls"
             xmlns:vm="clr-namespace:Passwords.ViewModels"
             mc:Ignorable="d"  d:DesignWidth="400" d:DesignHeight="300" >
    <UserControl.Template>
        <ControlTemplate TargetType="{x:Type UserControl}">
            <ControlTemplate.Resources>
                <ExponentialEase x:Key="easeOut" EasingMode="EaseOut" Exponent="5.0"/>
            </ControlTemplate.Resources>
            <Grid Margin="0,5,10,0" >
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="*"/>
                    <RowDefinition Height="auto"/>
                </Grid.RowDefinitions>
                <Grid.InputBindings>
                    <KeyBinding Key="Enter" Command="{x:Static vm:Commands.LoginCommand}" CommandParameter="{Binding ElementName= passwordBox}"/>
                </Grid.InputBindings>
                <StackPanel VerticalAlignment="Top" Margin="10,5,10,-50">
                    <TextBlock Text="{Binding rs.LoginLogin, Source={StaticResource locale}}" FontSize="48" FontWeight="Light" />
                    <TextBlock Text="{Binding BackupName}" FontSize="20" TextWrapping="Wrap" />
                </StackPanel>

                <StackPanel  VerticalAlignment="Top" HorizontalAlignment="Right" x:Name="appBtnPanel"
                        Margin="0,0,-4,0" Orientation="Horizontal">
                    <Button x:Name="backupBtn" Content="{Binding rs.LoginBackupAndRestoreBtn, Source={StaticResource locale}}" Style="{StaticResource radioLikeButtonStyle}"  Command="{x:Static vm:Commands.ShowBackupsCommand}">
                        <Button.RenderTransform>
                            <TranslateTransform/>
                        </Button.RenderTransform>
                    </Button>
                    <Separator x:Name="appSep" Style="{StaticResource lineSepStyle}">
                        <Separator.RenderTransform>
                            <TranslateTransform/>
                        </Separator.RenderTransform>
                    </Separator>
                    <Button x:Name="settingsBtn" Content="{Binding rs.SettingsBtn, Source={StaticResource locale}}" Style="{StaticResource radioLikeButtonStyle}"  Command="{x:Static vm:Commands.ShowSettingsCommand}">
                        <Button.RenderTransform>
                            <TranslateTransform/>
                        </Button.RenderTransform>
                    </Button>
                    <Separator x:Name="appSep2" Style="{StaticResource lineSepStyle}">
                        <Separator.RenderTransform>
                            <TranslateTransform/>
                        </Separator.RenderTransform>
                    </Separator>
                    <Button x:Name="changePwBtn" Content="{Binding rs.LoginChangePassswordBtn, Source={StaticResource locale}}" Style="{StaticResource radioLikeButtonStyle}"  Command="{x:Static vm:Commands.ShowChangePasswordCommand}">
                        <Button.RenderTransform>
                            <TranslateTransform/>
                        </Button.RenderTransform>
                    </Button>
                </StackPanel>

                <StackPanel Grid.Row="1" x:Name="stack2" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0" >
                    <StackPanel.Resources>
                        <Style TargetType="PasswordBox">
                            <Setter Property="FontSize" Value="16"/>
                        </Style>
                    </StackPanel.Resources>

                    <TextBlock Text="{Binding rs.LoginEnterMasterPassword, Source={StaticResource locale}}" FontSize="14" Margin="0,0,0,5"/>
                    <StackPanel Orientation="Horizontal" >
                        <PasswordBox x:Name="passwordBox" Width="240" controls:FocusContainer.FocusDelay="0:0:0.25"  />
                        <Button HorizontalAlignment="Right" Command="{x:Static vm:Commands.LoginCommand}" Padding="-2" Margin="-4,0,0,0" CommandParameter="{Binding ElementName= passwordBox}">
                            <Image Width="24" Height="24" Source="/Passwords;component/DarkImages/appbar.next.rest.png" />
                        </Button>
                    </StackPanel>
                </StackPanel>
                <StackPanel Grid.Row="1" x:Name="errorPanel" VerticalAlignment="Center" HorizontalAlignment="Center" Visibility="Collapsed">
                    <StackPanel.InputBindings>
                        <KeyBinding Key="Esc" Command="{x:Static vm:Commands.ShowLoginCommand}"/>
                    </StackPanel.InputBindings>
                    <TextBlock Text="{Binding rs.LoginPasswordDidNotMatch, Source={StaticResource locale}}" Foreground="{DynamicResource AppAccentBrush}" />
                    <Button x:Name="okBtn" Content="{Binding rs.Ok, Source={StaticResource locale}}" Width="100" Margin="0,20,0,5" HorizontalAlignment="Center"
                                Command="{x:Static vm:Commands.ShowLoginCommand}"/>
                </StackPanel>
                <StackPanel Grid.Row="1" x:Name="busyPanel"  Visibility="Collapsed" VerticalAlignment="Center" HorizontalAlignment="Center">
                    <TextBlock Text="{Binding rs.LoginLoggingIn, Source={StaticResource locale}}" HorizontalAlignment="Center" Margin="4"/>
                    <ProgressBar x:Name="pbar" IsIndeterminate="True" IsEnabled="False" Width="200" Height="16"/>
                </StackPanel>

                <CheckBox Content="{Binding rs.LoginHostSyncService, Source={StaticResource locale}}" Grid.Row="2" VerticalAlignment="Bottom" HorizontalAlignment="Left" 
                          Foreground="{DynamicResource AppForeground}"
                          Margin="5" IsChecked="{Binding IsServiceEnabled}"/>

                <!--Footer:-->
                <Border BorderThickness="0,0,0,0" Grid.Row="2" BorderBrush="{DynamicResource AppForeground}">
                    <StackPanel x:Name="footerPanel"  Orientation="Horizontal" Margin="10,8,10,0"  HorizontalAlignment="Center">
                        <StackPanel.Resources>
                            <Style TargetType="Button" BasedOn="{StaticResource radioLikeButtonStyle}" />
                        </StackPanel.Resources>
                        <Button x:Name="about" Content="{Binding rs.LoginAboutBtn, Source={StaticResource locale}}" FontSize="14" Command="{x:Static vm:Commands.AboutCommand}" >
                            <Button.RenderTransform>
                                <TranslateTransform x:Name="aboutTranslate"/>
                            </Button.RenderTransform>
                        </Button>
                    </StackPanel>
                </Border>


            </Grid>
           
            <ControlTemplate.Triggers>
                <DataTrigger Binding="{Binding LoginError}" Value="True">
                    <Setter Property="Panel.Visibility" Value="Visible" TargetName="errorPanel"/>
                    <Setter Property="Panel.Visibility" Value="Hidden" TargetName="stack2"/>
                    <Setter Property="controls:FocusContainer.IsFocused" TargetName="okBtn" Value="true"/>
                </DataTrigger>

                <MultiDataTrigger>
                    <MultiDataTrigger.Conditions>
                        <Condition Binding="{Binding AppDisplayMode}" Value="{x:Static models:AppDisplayMode.Login}" />
                        <Condition Binding="{Binding LoginError}" Value="False" />
                    </MultiDataTrigger.Conditions>
                    <Setter Property="controls:FocusContainer.IsFocused" Value="true" TargetName="passwordBox" />
                </MultiDataTrigger>
                <DataTrigger Binding="{Binding AppDisplayMode}" Value="{x:Static models:AppDisplayMode.Login}">
                    <DataTrigger.EnterActions>
                        <RemoveStoryboard BeginStoryboardName="hiddenStoryboard"/>
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation Storyboard.TargetName="about" Storyboard.TargetProperty="Opacity" From="0" To="1" Duration="0:0:0.5" EasingFunction="{StaticResource easeOut}"/>
                                <DoubleAnimation From="80" To="0" Storyboard.TargetName="about" Storyboard.TargetProperty="RenderTransform.Y" Duration="0:0:0.3" EasingFunction="{StaticResource easeOut}"/>
                                <DoubleAnimation Storyboard.TargetName="stack2" Storyboard.TargetProperty="Opacity" From="0" To="1" Duration="0:0:0.5" EasingFunction="{StaticResource easeOut}"/>
                                <DoubleAnimation Storyboard.TargetName="appBtnPanel" Storyboard.TargetProperty="Opacity" From="0" To="1" Duration="0:0:1" EasingFunction="{StaticResource easeOut}"/>
                                <DoubleAnimation From="32" To="0" Storyboard.TargetName="backupBtn" Storyboard.TargetProperty="RenderTransform.X" Duration="0:0:1" EasingFunction="{StaticResource easeOut}"/>
                                <DoubleAnimation From="24" To="0" Storyboard.TargetName="appSep2" Storyboard.TargetProperty="RenderTransform.X" Duration="0:0:1" EasingFunction="{StaticResource easeOut}"/>
                                <DoubleAnimation From="24" To="0" Storyboard.TargetName="settingsBtn" Storyboard.TargetProperty="RenderTransform.X" Duration="0:0:1" EasingFunction="{StaticResource easeOut}"/>
                                <DoubleAnimation From="16" To="0" Storyboard.TargetName="appSep" Storyboard.TargetProperty="RenderTransform.X" Duration="0:0:1" EasingFunction="{StaticResource easeOut}"/>
                                <DoubleAnimation From="8" To="0" Storyboard.TargetName="changePwBtn" Storyboard.TargetProperty="RenderTransform.X" Duration="0:0:1" EasingFunction="{StaticResource easeOut}"/>
                            </Storyboard>
                        </BeginStoryboard>
                    </DataTrigger.EnterActions>
                    <DataTrigger.ExitActions>

                        <BeginStoryboard x:Name="hiddenStoryboard">
                            <Storyboard >
                                <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Duration="0:0:0">
                                    <ObjectAnimationUsingKeyFrames.KeyFrames>
                                        <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{x:Static Visibility.Hidden}"/>
                                    </ObjectAnimationUsingKeyFrames.KeyFrames>
                                </ObjectAnimationUsingKeyFrames>
                            </Storyboard>
                        </BeginStoryboard>

                    </DataTrigger.ExitActions>
                </DataTrigger>
                <DataTrigger Binding="{Binding IsBusy}" Value="True">
                    <Setter Property="Panel.Visibility" Value="Visible" TargetName="busyPanel"/>
                    <Setter Property="Panel.Visibility" Value="Hidden" TargetName="stack2"/>
                    <Setter Property="Control.Visibility" Value="Hidden" TargetName="appBtnPanel"/>
                </DataTrigger>
                <!--<DataTrigger Binding="{Binding AppDisplayMode}" Value="{x:Static models:AppDisplayMode.Login}">
                    <Setter Property="controls:FocusContainer.IsFocused" Value="true" TargetName="passwordBox"/>
                </DataTrigger>-->

            </ControlTemplate.Triggers>
        </ControlTemplate>
    </UserControl.Template>
</UserControl>
